#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/8 17:35
# @Author  : jeff
# @FileName: response
from flask import jsonify
from loguru import logger


def create_response(status, info=None, message=None):
    if status.value['code'] == 4001 or status.value['code'] == 2001 or status.value['code'] == 3001:
        res = {
            'code': status.value['code'],
            'message': message,
            'info': info
        }
    else:
        logger.info(f'status:{status.value["code"]},message:{status.value["message"]},info:{info}')
        res = {
            'code': status.value['code'],
            'message': status.value['message'],
            'info': info
        }

    return jsonify(res)


def response(*args):
    if len(args) == 1 and not isinstance(args[0], tuple):
        return create_response(status=args[0])
    elif len(args[0]) == 2:
        return create_response(status=args[0][0], info=args[0][1])
    elif len(args[0]) == 3:
        return create_response(status=args[0][0], info=args[0][1], message=args[0][2])
    else:
        logger.error('response parameter error')
        return 'response parameter error'
